Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(MessageEmbed): Skip validation of field when inside a message #3894

Merged
merged 10 commits into from
Mar 8, 2020
Merged

fix(MessageEmbed): Skip validation of field when inside a message #3894

merged 10 commits into from
Mar 8, 2020

Conversation

MattIPv4
Copy link
Contributor

@MattIPv4 MattIPv4 commented Mar 4, 2020

Please describe the changes this PR makes and why it should be merged:

This should fix #3892 by skipping validation on embeds when they are part of a parent message.

The library works fine with this change, but per discussion in #library-discussion, we can't actually reproduce the buggy embed to test this. One should be able to assume this will work though (assuming I've added the flag in the right places) as it is disabling the validation that was throwing the error.

Status

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

Semantic versioning classification:

  • This PR changes the library's interface (methods or parameters added)
    • This PR includes breaking changes (methods removed or renamed, parameters moved or removed)
  • This PR only includes non-code changes, like changes to documentation, README, etc.

src/structures/MessageEmbed.js Outdated Show resolved Hide resolved
src/structures/MessageEmbed.js Outdated Show resolved Hide resolved
src/structures/MessageEmbed.js Show resolved Hide resolved
src/structures/MessageEmbed.js Outdated Show resolved Hide resolved
@MattIPv4 MattIPv4 requested review from SpaceEEC and iCrawl March 6, 2020 11:40
@MattIPv4
Copy link
Contributor Author

MattIPv4 commented Mar 6, 2020

Been running this fork on my bot that originally found this issue for a while now, hasn't thrown this error so I'm pretty confident this flag is working as intended.

Copy link
Member

@SpaceEEC SpaceEEC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing something like [{ name: 'foo', value: 'bar' }, { name: 'foo', value: 'bar' }] to addFields or spliceFields on embeds skipping validation breaks the fields property:

// Assume this embed is taken from `Message#embeds` rather than being manually instantiated.
> new MessageEmbed({}, true).addFields([{ name: 'foo', value: 'bar' }, { name: 'foo', value: 'bar' }]).fields
[
  Array {
    '0': { name: 'foo', value: 'bar' },
    '1': { name: 'foo', value: 'bar' }
  }
]

Compared to:

> new MessageEmbed({}).addFields([{ name: 'foo', value: 'bar' }, { name: 'foo', value: 'bar' }]).fields
[
  { name: 'foo', value: 'bar', inline: false },
  { name: 'foo', value: 'bar', inline: false }
]

The fix is to Array#flat the fields, like normalizeFields does too.

While modifying those embeds is not exactly a recommended use-case, it is a "supported" one and shouldn't break.

@MattIPv4 MattIPv4 requested a review from SpaceEEC March 6, 2020 13:40
- dead code
  discord.js does not use those methods interally and won't in the future, as Discord
  does not emit any partial embed updates and doing so in the future seems unlikely.
- a breaking change (an incompatible api change)
  Although it's not recommended to do, users can modify
  received embeds without cloning them, e.g.:
  const embed = message.embeds[0].addField('some title', '');
  (replace '' with some function call; this is just an example)
  This would no longer throw a synchronous error (breaking change),
  but at a later point when actually sending it. (poorer to debug)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Discord sending embeds with no name, causing lib exception
5 participants